﻿using System.Linq;
using System.Web.Mvc;
using Project.DAL.Repository;

namespace Project.WebUI.Areas.Admin.Controllers
{
    public class ManageContactController : Controller
    {
        #region "private"
        private readonly IUserRepository _userRepository;
        private readonly IDepositRepository _depositRepository;
        private readonly IWithDrawRepository _withDrawRepository;
        private readonly IUserService _userService;
        private readonly ICountryRepository _countryRepository;
        private readonly IContactRepository _contactRepository;        
        private readonly IStoreSecureRepositoty _storeSecureRepositoty;
        private const string Controller = "ManageContact";

        public ManageContactController(
            IUserRepository userRepository,
            IDepositRepository depositRepository,
            IWithDrawRepository withDrawRepository,
            IUserService userService,
            ICountryRepository countryRepository,
            IContactRepository contactRepository,            
            IStoreSecureRepositoty storeSecureRepositoty)
        {
            _userRepository = userRepository;
            _depositRepository = depositRepository;
            _withDrawRepository = withDrawRepository;
            _userService = userService;
            _countryRepository = countryRepository;
            _contactRepository = contactRepository;
            _storeSecureRepositoty = storeSecureRepositoty;
        }

        #endregion                        
        
        public ActionResult LoadAjax(int index, int numpage)
        {
            var lisContact = _contactRepository.GetMany(null, c => c.OrderByDescending(t => t.CreatedTime));
            ViewBag.result = lisContact.Count();
            return PartialView("_MainContent", lisContact);
        }

        public ActionResult UpdateStatus(int id, int status)
        {
            var contact = _contactRepository.GetById(id);
            if (status == 1)
            {
                contact.Active = false;
                _contactRepository.SaveChanges();
                ViewBag.status = false;
                ViewBag.id = id;
                ViewBag.controller = Controller;
                return PartialView("_UpdateStatus");
            }

            contact.Active = true;
            _contactRepository.SaveChanges();
            ViewBag.status = true;
            ViewBag.id = id;
            ViewBag.controller = Controller;
            return PartialView("_UpdateStatus");
        }

        public ActionResult Index()
        {
            if (Session["admin"] == null)
            {
                return RedirectToAction("Login");
            }
            return View();
        }        
    }
}
